import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import local_get from '@dfeidao/atom-mobile/local/get';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
import alert from '@dfeidao/atom-mobile/msgbox/alert';
import toast from '@dfeidao/atom-mobile/msgbox/toast';
import render from '@dfeidao/atom-mobile/render/render';
// delete
import a001 from './a001';
export default async function a004(fd: IFeidaoAiMobile, e: Event, args: { job_no: string, secId: string, rowId: string, rowMap: {} }) {
	const del_index = Number(args.rowId);
	const index = await alert('提示', '是否确认删除', ['是', '否'], false);
	// 如果是选择 否:1 则停止向下执行
	if (index === 1) { return; }
	const job_no = args.job_no;
	const productid = await local_get(fd, 'productid');
	const res_msg = await nodejs<{ code: number }>('app-arrange-homework/s002', { filter: { job_no }, productid });
	if (res_msg.code === 1) {
		const newData = fd.data.dt as [];
		newData.splice(del_index, 1);
		if (newData.length > 10) {
			render(fd, { dt: newData });
		} else {
			await a001(fd);
		}
		// 关闭删除的列表数据
		await args.rowMap[`${args.secId}${args.rowId}`].props.closeRow();
		await toast({
			text: '删除成功',
			position: 'center',
			type: 'success'
		});
	} else {
		await toast({
			text: '失败',
			position: 'center',
			type: 'danger'
		});
	}
}
